fix(usage): only publish settled /usage reads — kill phantom quota alerts#139
Merged
Conversation
…erts The quota-alerts loop pushed "week: 78%" while the live week was 2%. Root cause is in _poll_usage_modal: it returned even an UNSETTLED read (`return info if (resolved or info is not None)`), and _capture_with_scrollback reads ~100 lines back — which can still hold a PREVIOUS /usage render. After the weekly reset that stale render shows last week's high pct; the parser surfaces it and quota_alerts treats it as a fresh 50%/75% crossing. Two changes: - _poll_usage_modal returns None unless two consecutive captures agree (drop the stale-frame fallback). A missed poll is harmless; the loop retries on the next cadence. - clear the pane scrollback (new _clear_pane_history) and Escape any leftover modal before /usage, so a pre-reset render can't be parsed as the current week. Tests: a settled read is published; an oscillating (never-settling) read returns None instead of the last frame. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
@Alexes_claude_bot pushed three quota alerts in one minute —
🟡 week: 68%,🟡 week: 68%,🟠 week: 78%— while the live weekly usage was 2% (confirmed via/usage: session 7%, week 2%, week-Sonnet 0%).Proof the 78% was never real: the week resets Jun 21; usage only climbs within a week, so it can't read 78% at 14:31 and 2% an hour later. The 78% was a stale pre-reset value (last week's high), surfaced by the usage poller.
Root cause
_poll_usage_modalwaits for two consecutive agreeing captures (resolved), but the fallback returned an unsettled frame anyway:And
_capture_with_scrollbackreads ~100 lines of scrollback, which can still contain a previous/usagerender. After the weekly reset, the parser walks that stale render andextract_usage_breakdowncan surface last week's high pct.quota_alerts(process-local baseline, reset by the bot's frequent restarts) then reads0 → 78and fires phantom50%/75%crossings. Network flaps (the same instability behind the bot's restarts) bunched/duplicated the delivery into one minute.Fix
_poll_usage_modalreturnsNoneunless two consecutive captures agree. A missed poll is harmless; the loop retries on the next 10-min cadence._clear_pane_historyclears the pane buffer, and anEscapedismisses any leftover modal/feedback-prompt, so a pre-reset render can't be parsed as the current week.Tests
tests/ccbot/bot/test_usage_window.py:Noneinstead of the last frame (the old bug).Full suite green (742 passed), pyright (strict,
src/ccbot) + ruff clean.🤖 Generated with Claude Code